function Session(option) {
	this.nick = Math.floor(Math.random() * 1e6).toString();
	this.id = Math.floor(Math.random() * 1e10).toString();
	this.timestamp = new Date();
    this._words = {};
    this._wordsList = [];
    this._lastWord = new Date();
    
    //verify
    this._ip = option.ip || '';
}
Session.prototype.setRate = function(){
    this._lastWord = new Date();
};
Session.prototype.preCheck = function(str){
        //true 允许  false 禁止
        var temp = ';'
        var flag = false;
        while(this._wordsList.length > 25){
            temp = this._wordsList.shift();
            delete this._words[temp];
        }
        if (typeof this._words[str] == 'undefined'){
            this._words[str] = 1;
            this._wordsList.push(str);
            flag = true;
        }else{
            this._words[str]++;
            if (this._words[str] > 2)
                flag = false;
            else
                flag = true;
        }
        if (flag && new Date() - this._lastWord <= 1500){
            flag = false;
        }
        return flag;
}
Session.prototype.setNick = function(nick){
    var len = function(b) {
        if (typeof b == "undefined") {
            return 0
        }
        var a = b.match(/[^\x00-\x80]/g);
        return (b.length + (!a ? 0 : a.length))
    };
    var _nick = nick;
    try{
        _nick = decodeURIComponent(nick);
    }catch(e){}
	if (!_nick || len(_nick) > 11 || _nick.toLocaleLowerCase().indexOf('admin') != -1
         || _nick.toLocaleLowerCase().indexOf('้') != -1
    ) {
		return false;
	}
    this.nick = nick;
    return true;
};
Session.prototype.poke = function() {
	this.timestamp = new Date();
};
exports.Session = Session;
